package spe.ui.editor.command;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.commands.Command;

import spe.model.notation.SPEMDiagram;
import spe.model.spem.NodeElement;
import spe.ui.editor.part.GraphEditPart;

public class ElementCreatingCommand extends Command
{
	private static final String defaultName = "<Element Name>";
	
	private NodeElement node;
	private Point location;
	private SPEMDiagram diagram;
	
	@Override
	public void execute()
	{
		setPosition();
	}
	
	protected void setPosition() 
	{
		//System.out.println(String.format("[ElementCreatingCommand] Diagram: %s; NodeElement %s; Location: %s", diagram, node, location));
		if (location != null) 
		{
			//Point pos = node.getPosition();
			node.setPosition(location);
			node.setContainer(diagram);
			diagram.addElement(node);
		}		
	}
	
	@Override
	public void undo()
	{	
		SPEMDiagram diagram = node.getContainer();
		diagram.removeElement(node);
	}
	
	public void setLocation(Point location)
	{
		this.location = location;
	}
	
	public void setParent(SPEMDiagram dgrm)
	{
		diagram = dgrm;
	}
	
	public void setElement(NodeElement elmnt)
	{
		node = elmnt;
		node.setName(defaultName);
	}
}
